import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import { resolve } from "path";
import Pages from "vite-plugin-pages";
import Layouts from "vite-plugin-vue-layouts";
import AutoImport from "unplugin-auto-import/vite";
import Components from "unplugin-vue-components/vite";
import Icons from "unplugin-icons/vite";
import IconsResolver from "unplugin-icons/resolver";
import VueI18n from "@intlify/unplugin-vue-i18n/vite";
import path from "path";

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    Pages({
      dirs: "src/views",
      exclude: ["**/components/*.vue"],
    }),
    Layouts(),
    Components({
      // By default, 'src/components' will be included in the dirs
      dts: true,
      resolvers: [IconsResolver()],
    }),
    Icons({
      scale: 1.6, // Scale of icons against 1em
      compiler: "vue3", // 'vue2', 'vue3', 'jsx'
    }),
    // https://github.com/intlify/bundle-tools/tree/main/packages/unplugin-vue-i18n
    VueI18n({
      runtimeOnly: true,
      compositionOnly: true,
      fullInstall: true,
      include: [path.resolve(__dirname, "locales/**")],
    }),
    AutoImport({
      dts: true,
      include: [
        /\.[tj]sx?$/, // .ts, .tsx, .js, .jsx
        /\.vue$/,
        /\.vue\?vue/, // .vue
      ],
      eslintrc: {
        enabled: true, // <-- this
      },
      // global imports to register
      // preset: https://github.com/antfu/unplugin-auto-import/tree/main/src/presets
      imports: [
        // presets
        "vue",
        "vue-router",
        "vue-i18n",
        // custom
        {
          axios: [
            // default imports
            ["default", "axios"], // import { default as axios } from 'axios',
          ],
          "[package-name]": [
            "[import-names]",
            // alias
            ["[from]", "[alias]"],
          ],
        },
        // example type import
        {
          from: "vue-router",
          imports: ["RouteLocationRaw"],
          type: true,
        },
      ],
    }),
  ],
  server:{
   host: '0.0.0.0',
   proxy:{
    '/api': {
      target: 'http://10.6.110.137:8020', // 接口的域名
      secure: false, // 如果是https接口，需要配置这个参数
      changeOrigin: true, // 如果接口跨域，需要进行这个参数配置
      rewrite:(path : any) => {
        console.log(path)
       return path.replace(/^\/api/, '')
      }
    },

   }
  },
  resolve: {
    alias: {
      "@": resolve(__dirname, "src"),
    },
  },
});
